package com.kgc.scd.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Collection;

/**
 * Created On : 2022/10/19 0019.
 * <p>
 * Author : shiguangchuan
 * <p>
 * Description: 分页结果返回类
 */
@Data
@ApiModel(value = "分页结果返回类")
public class PageSupport<T> {

    /**
     * 当前页面
     */
    @ApiModelProperty(value = "当前页面")
    private int pageNo;

    /**
     * 页面条数
     */
    @ApiModelProperty(value = "页面条数")
    private int pageSize;

    /**
     * 总条数
     */
    @ApiModelProperty(value = "总条数")
    private int totalCount;

    /**
     * 总页数
     */
    @ApiModelProperty(value = "总页数")
    private int totalPage;

    /**
     * 分页数据
     */
    @ApiModelProperty(value = "分页数据")
    private Collection<T> pageData;

    /**
     * 当总条数确定时，总页数也确定了
     */
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        this.totalPage = this.totalCount % this.pageSize == 0
                ? this.totalCount / this.pageSize
                : this.totalCount / this.pageSize + 1;
    }
}
